home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CUJ9206.ARJ / 1006028A < prev    next >
Text File  |  1992-06-02  |  3KB  |  104 lines

  1. //    TESTPROG.C
  2. //
  3. //
  4. //    This program demonstrates the use of hardware locks (using
  5. //    FAKELOCK to simulate the hardware lock).  TESTPROG has four
  6. //    functions, two of which (func2 and func3) are designed to be
  7. //    used frequently when running TESTPROG.  TESTPROG calls FAKELOCK
  8. //    when the TESTPROG starts and every time func2 and func3 are called.
  9. //
  10. //    The program TESTLOCK was used to determine what values FAKELOCK
  11. //    would return for the given parameters.
  12. //
  13. //    The function CALL_LOCK calls FAKELOCK.
  14. //    CALL_LOCK gives TESTPROG a uniform response to failing
  15. //    the hardware lock test.  Instead of just exiting the program,
  16. //    CALL_LOCK gives the user the chance to restore the lock
  17. //    and continue.  This was done so that any data in memory 
  18. //    might be saved before the program returned to DOS.
  19.  
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include "fakelock.h"
  23.  
  24. //    function prototypes
  25. void CALL_LOCK( char *incode );
  26. void func1( char* msg );
  27. void func2( char* msg );
  28. void func3( char* msg );
  29. void func4( char* msg );
  30.  
  31. void main( void )
  32. {
  33.   CALL_LOCK( "abcdefgh" );
  34.  
  35.   func1( "\nfirst  time in function 1" );
  36.   func2( "\nfirst  time in function 2" );
  37.   func3( "\nfirst  time in function 3" );
  38.   func2( "\nsecond time in function 2" );
  39.   func2( "\nthird  time in function 2" );
  40.   func3( "\nsecond time in function 3" );
  41.   func2( "\nfourth time in function 2" );
  42.   func4( "\nfirst  time in function 4" );
  43.  
  44.   printf("\nProgram finished normally");
  45. };
  46.  
  47. void func1( char* msg )
  48. {
  49.   printf("%s", msg );
  50. };
  51.  
  52. void func2( char* msg )
  53. {
  54.   CALL_LOCK( "abcdefgh" );
  55.   printf("%s", msg );
  56. };
  57.  
  58. void func3( char* msg )
  59. {
  60.   CALL_LOCK( "abcdefgh" );
  61.   printf("%s", msg );
  62. };
  63.  
  64. void func4( char* msg )
  65. {
  66.   char test[96];
  67.  
  68.   printf("\nEnter any lock parameter you want (only 'abcdefgh'"
  69.      " will find lock): ");
  70.   gets( test );
  71.   CALL_LOCK( test );
  72.   printf("%s", msg );
  73. };
  74.  
  75. void CALL_LOCK( char *incode )
  76. {
  77.   int  key;
  78.   char lock[96];
  79.   int  results = 0;
  80.  
  81.   printf("\nWhich lock is to be called (1 or 2): ");
  82.   gets( lock );
  83.   key = atoi( lock );
  84.  
  85.   while (results != 19334)
  86.   {
  87.     if ( (results = FAKELOCK( incode, key )) != 19334 )
  88.     {
  89.       printf("FAKE LOCK returned %d, that did not match the known key",
  90.           results );
  91.       printf("\nEnter another lock to try (0 to exit to DOS, or 1 or 2): ");
  92.       gets( lock );
  93.       key = atoi( lock );
  94.  
  95.       if ( key == 0 )
  96.       {
  97.     printf("Program ended because it could not find hardware lock");
  98.     exit( 0 );
  99.       }
  100.     }
  101.   }
  102.   return;
  103. }
  104.